package cn.cj.handle;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.cj.util.ResultUtil;
import cn.cj.vo.Result;

public class ExceptionHandle {
    private final static Logger logger = Logger.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e) {
        if (e instanceof JobException) {
            JobException jobException = (JobException) e;
            return ResultUtil.error(jobException.getCode(), jobException.getMessage());
        } else {
            logger.error("【系统异常 】{}", e);
            return ResultUtil.error(-1, "未知错误");
        }

    }
}
